using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.EntityFramework;

namespace DynSim.Basics
{
    [Serializable]
    public class Camera : IRotatable, IMoveable
    {
        public Matrix view, projection;
        public readonly Vector3 position, lookAt, upVector;

        public Camera(Vector3 position, Vector3 lookAt, float fov, float aspectRatio)
        {
            this.view = Matrix.CreateLookAt(position, lookAt, Vector3.Up);
            this.projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, 1f, 100000f);

            this.position = position;
            this.lookAt = lookAt;
        }

        public Camera(Vector3 position, Vector3 lookAt, float fov, float aspectRatio, float nearPlane, float farPlane)
        {
            this.view = Matrix.CreateLookAt(position, lookAt, Vector3.Up);
            this.projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, nearPlane, farPlane);

            this.position = position;
            this.lookAt = lookAt;
        }

        public Camera(Vector3 position, Vector3 lookAt, Vector3 upVector, float fov, float aspectRatio)
        {
            this.view = Matrix.CreateLookAt(position, lookAt, upVector);
            this.projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, 1f, 100000f);

            this.position = position;
            this.lookAt = lookAt;
            this.upVector = upVector;
        }

        public Camera(Vector3 position, Vector3 lookAt, Vector3 upVector, float fov, float aspectRatio, float nearPlane, float farPlane)
        {
            this.view = Matrix.CreateLookAt(position, lookAt, upVector);
            this.projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, nearPlane, farPlane);

            this.position = position;
            this.lookAt = lookAt;
            this.upVector = upVector;
        }

        public void Rotate(Vector3 rotation)
        {
            //TODO: Camera Rotation
            //this.view = Matrix.CreateLookAt(position, lookAt, upVector);
        }

        public void Move(Vector3 position)
        {
            this.view = Matrix.CreateLookAt(position, lookAt, upVector);
        }

        public void LookAt(Vector3 at)
        {
            this.view = Matrix.CreateLookAt(position, at, upVector);
        }
    }
}
